all files / timePicker/ clockNumber.vue

37.5% Statements 9/24
40% Branches 4/10
20% Functions 1/5
26.67% Lines 4/15
1 branch Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83          1×   1×                           1×                                                                                                                          
//
//
//
//
 
import {isInner} from './timeUtils'
 
const positions = [
    [0, 5],
    [54.5, 16.6],
    [94.4, 59.5],
    [109, 114],
    [94.4, 168.5],
    [54.5, 208.4],
    [0, 223],
    [-54.5, 208.4],
    [-94.4, 168.5],
    [-109, 114],
    [-94.4, 59.5],
    [-54.5, 19.6]
]
const innerPositions = [
    [0, 40],
    [36.9, 49.9],
    [64, 77],
    [74, 114],
    [64, 151],
    [37, 178],
    [0, 188],
    [-37, 178],
    [-64, 151],
    [-74, 114],
    [-64, 77],
    [-37, 50]
]
 
export default {
  props: {
    value: {
      type: Number,
      default: 0
    },
    type: {
      type: String,
      default: 'minute',
      validator (val) {
        return ['hour', 'minute'].indexOf(val) !== -1
      }
    },
    selected: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    isInner () {
      return isInner(this)
    },
    numberClass () {
      return {
        selected: this.selected,
        inner: this.isInner
      }
    },
    numberStyle () {
      let pos = this.value
      if (this.type === 'hour') {
        pos %= 12
      } else {
        pos = pos / 5
      }
      let transformPos = positions[pos]
      if (this.isInner) transformPos = innerPositions[pos]
      const [x, y] = transformPos
      return {
        transform: `translate(${x}px, ${y}px)`,
        left: this.isInner ? 'calc(50% - 14px)' : 'calc(50% - 16px)'
      }
    }
  }
}